﻿using chihuopig.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;

namespace chihuopig.Web.verfiy
{
    public class CheckNameIsRepAttribute: ValidationAttribute
    {
        string _Table;
        public CheckNameIsRepAttribute(string table)
        {
            _Table = table;
        }
        public override bool IsValid(object value)
        {
            long IsrepId= DBService.Sqlclient.Ado.SqlQuery<long>($"select count(*) from {_Table} where Name='{value}' and Isdelete='0' ").Single();
            if (IsrepId>0)
            {
                return false;
            }

            return true;
        }
    }
}
